package cn.zfs.datasource.entity.model;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class DataSource extends DataSourceProperties {

    // 协议 jdbc:mysql://10.4.82.34:3306/car_server
    private String agreement;
    // 数据库 类型
    private String dataBase;
    // ip 端口 数据库名
    private String ip, port, param;

    @Override
    public String getUrl() {
        StringBuffer url = new StringBuffer();
        url.append(agreement).append(":").append(dataBase).append("://")
                .append(ip).append(":").append(port).append("/").append(super.getTableSchema());
        if (param != null) {
            url.append("?").append(param);
        }
        return url.toString();
    }

    public static void main(String[] args) {
        DataSource dataSource = new DataSource();
        dataSource.setAgreement("jdbc");
        dataSource.setDataBase("mysql");
        dataSource.setIp("db.zhangafusheng.cn");
        dataSource.setPort("3306");
        System.out.println(dataSource.getUrl());
    }
}
